package com.situ.achievementsystem.employee.service;

import java.util.List;

import com.situ.achievementsystem.employee.dao.EmployeeDao;
import com.situ.achievementsystem.employee.model.EmployeeModel;

//import sun.security.util.Password;



public class EmployeeService {

private EmployeeDao dao = new EmployeeDao();
	
	public String insert(EmployeeModel model) {
		return selectModel(model) == null?dao.insert(model):null;
	}
	
	public String delete(EmployeeModel model) {
		return dao.delete(model);
	}
	
	public String update(EmployeeModel model) {
		return dao.update(model);
	}
	
	public List<EmployeeModel> selectList(EmployeeModel model) {
		String code = model.getCode();
		code = code ==null || code.trim().isEmpty()?"":code;
		model.setCode("%" + code + "%");
		String name = model.getName();
		name = name ==null || name.trim().isEmpty()?"":name;
		model.setName("%" + name + "%");
		String codeDept = model.getCodeDept();
		codeDept = codeDept ==null || codeDept.trim().isEmpty()?"":codeDept;
		model.setCodeDept("%" + codeDept + "%");
		String nameDept = model.getNameDept();
		nameDept = nameDept ==null || nameDept.trim().isEmpty()?"":nameDept;
		model.setNameDept("%" + nameDept + "%");
		return dao.select(model);
	}
	
	public EmployeeModel selectModel(EmployeeModel model) {
		EmployeeModel temp = new EmployeeModel();
		temp.setCode(model.getCode());
		List<EmployeeModel> list = dao.select(model);
		if(list==null || list.isEmpty())
			return null;
		return list.get(0);
	}

	public String login(EmployeeModel model) {
		EmployeeModel m1 = new EmployeeModel(model.getCode());
		List<EmployeeModel> list = dao.select(m1);
		if(list==null||list.isEmpty()) {
			return "0";
		}
		EmployeeModel m2 = list.get(0);
		if(m2.getPass().equals(model.getPass())) {
			return "1";
		}else {
			return "2";
		}
	}

	public String resetpass(EmployeeModel model) {
		model.setPass("1234");
		return dao.updatepass(model);
	}
	
	public String updpass(EmployeeModel model) {
		return dao.updatepass(model);
	}

	public Object updDept(EmployeeModel model) {
		return dao.updateDept(model);
	}
	
}
